<template >
  <div class="add_con_form tl" v-loading="loading">
    <el-dialog
      :close-on-click-modal="false"
      title="编辑会员"
      :modal-append-to-body="false"
      :visible.sync="visible"
      :show="show"
      :before-close="closeDialog"
      @close="$emit('update:show', false)"
      class="tl size_13"
      width="800px"
    >
      <el-form
        :model="data"
        :rules="dataYZ"
        ref="data"
        class="mar_top"
        label-width="120px"
      >
        <el-form-item label="昵称" prop="nickname">
          <el-col :span="12">
            <el-input placeholder v-model="data.nickname" clearable></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="区号" prop>
          <el-col :span="12">
            <el-input placeholder v-model="data.quhao" clearable></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="电话" prop="tel">
          <el-col :span="12">
            <el-input placeholder v-model="data.tel" clearable></el-input>
          </el-col>
        </el-form-item>

        <!-- <el-form-item label="真实姓名" prop="name">
                        <el-col :span="12">
                    <el-input
                        placeholder=""
                        v-model="data.name"
                        clearable>
                    </el-input>
                        </el-col>
        </el-form-item>-->

        <!-- <el-form-item label="身份证ID" prop="card">
                        <el-col :span="12">
                    <el-input
                        placeholder=""
                        v-model="data.card"
                        clearable>
                    </el-input>
                        </el-col>
        </el-form-item>-->

        <el-form-item label="会员头像" prop="avatar">
          <el-col :span="12">
            <el-input
              v-model="data.avatar"
              autocomplete="off"
              class="mar_bottom_5"
            ></el-input>
            <uploadpic
              :piclink="data.avatar"
              :width="150"
              :height="150"
              :is_more="false"
              @send_pic="onSuccess"
            ></uploadpic>
          </el-col>
        </el-form-item>

        <!-- <el-form-item label="所在省市区" prop="address">
                       <el-col :span="12">
                        

                    <city-cascader  :level='3' size="large" :placeholder="selectedOptions.join('-')"  @change="handleChange" />

                        </el-col>
        </el-form-item>-->

        <el-form-item label="指定会员">
          <el-col :span="12">
            <el-radio v-model="data.designation" label="0">否</el-radio>
            <el-radio v-model="data.designation" label="1">是</el-radio>
          </el-col>
        </el-form-item>
        <el-form-item label="是否站长">
          <el-col :span="12">
            <el-radio v-model="data.is_webmaster" label="0">否</el-radio>
            <el-radio v-model="data.is_webmaster" label="1">是</el-radio>
          </el-col>
        </el-form-item>
        <el-form-item label="备注">
          <el-col :span="12">
            <el-input
              placeholder
              v-model="data.admin_remark"
              clearable
            ></el-input>
          </el-col>
        </el-form-item>

        <div class="mar_bottom_15">
          <span class="sizeColor size_13 sp_style"></span>
          <el-button
            :loading="$store.state.isLoading"
            size="medium"
            type="primary"
            @click.prevent="addUpdate('data')"
            >确定</el-button
          >
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>


<style lang="less" scoped>
</style>

<script>
import compressimgUpload from "@/components/currency/compressimgUpload.vue";
import uploadpic from "@/components/page/pic/up_pic";

import cityCascader from "@/components/currency/cityCascader/cityCascader";
export default {
  components: {
    compressimgUpload,
    cityCascader,
    uploadpic,
  },
  data() {
    var checkTitle = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("标题不能为空"));
      } else {
        callback();
      }
    };

    return {
      fileList: [],
      showImg: true,
      options: this.$addressJson,
      selectedOptions: [], //["福建省", "福州市", "台江区"]
      optionProps: {
        value: "y",
        label: "t",
        children: "z",
      },
      value: "",
      data: {
        id: "",
        nickname: "",
        tel: "",
        card: "",
        avatar: "",
        province: "",
        city: "",
        area: "",
        town: "",
        admin_remark: "",
        quhao: "",
        designation: "0",
      },
      loading: false,
      dataYZ: {
        //     title:[
        //     { validator: checkTitle, trigger: 'blur' }
        //     ],
      },
      visible: this.show,
    };
  },
  props: {
    show: Boolean,
    editId: String,
    clickNum: Number,
  },
  methods: {
    onSuccess(pic) {
      this.data.avatar = pic;
    },
    handleChange(value) {
      console.log(value);
      if (value) {
        for (var i = 0; i < value.length; i++) {
          console.log(value[i]);
          if (i == 0) this.data.province = value[i];
          if (i == 1) this.data.city = value[i];
          if (i == 2) this.data.area = value[i];
          if (i == 3) this.data.town = value[i];
        }
      }
    },

    closeDialog() {
      this.visible = false;
    },
    getDetails(id) {
      var data = {};
      data["id"] = id;
      this.$api.getUser.userEdit(data).then((res) => {
        this.data = res.data.result;
        this.selectedOptions = [
          this.data.province,
          this.data.city,
          this.data.area,
          this.data.town,
        ];
      });
    },
    addUpdate(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var params = {};
          params["id"] = this.data.id;
          params["nickname"] = this.data.nickname;
          params["tel"] = this.data.tel;
          params["card"] = this.data.card;
          params["province"] = this.data.province;
          params["city"] = this.data.city;
          params["area"] = this.data.area;
          params["town"] = this.data.town;
          params["avatar"] = this.data.avatar;
          params["quhao"] = this.data.quhao;
          params["designation"] = this.data.designation;
          params["admin_remark"] = this.data.admin_remark;
          params["name"] = this.data.name;
          params["is_webmaster"] = this.data.is_webmaster;
          this.$api.getUser.userSaveEdit(params).then((res) => {
            if (res.data.code == 200 && res.data.result != null) {
              this.$emit("parent", "这里刷新父页面");
              this.$fnc.alertSuccess({ text: "编辑成功" }); //成功弹出框
              this.visible = false;
            } else {
              this.$fnc.alertError(res.data.result); //失败弹出框
            }
          });
        }
      });
    },
  },
  watch: {
    show() {
      console.log(this.show);
      this.visible = this.show;
    },
    clickNum(id) {
      console.log("点击button次数", id);
      console.log("编辑ID=" + this.editId);
      this.getDetails(this.editId);
    },
  },
  mounted() {
    //this.getDetails(this.$route.query.id);
  },
  created() {},
};
</script>
